// ### 作业：创建一个学生表,里面有班级字段,里面最好有自己班上同学姓名,其它班级的姓名随机写,有个字段存储游戏的分值,先实现随机的数值写入,查询出各班级前三名的学生
let mysql=require("mysql")
let con=mysql.createConnection({host:"127.0.0.1",user:"root",password:"root",port:"3306",database:"student"})
con.connect();

//获取日期

let date=new Date();
let time=date.getFullYear()+"/"+(date.getMonth()+1)+"/"+date.getDate()+"/"+date.getHours()+":"+date.getMinutes()+":"+date.getSeconds();

//随机生成
let score=Math.floor(Math.random()*101);
let clas=Math.ceil(Math.random()*4);

// //添加数据
// let insertsql="insert into stu values (null,'"+clas+"','何柳','"+score+"','"+time+"','"+time+"')"
// con.query(insertsql,(err,date)=>{
//     console.log(err)
//     console.log(date)

// })

let one="select * from stu where class=1 order by score  desc limit 3"
con.query(one,(err,data)=>{
     console.log(err)
    console.log(data)
})
let two="select * from stu where class=2 order by score  desc limit 3"
con.query(two,(err,data)=>{
     console.log(err)
    console.log(data)
})
let three="select * from stu where class=3 order by score  desc limit 3"
con.query(three,(err,data)=>{
     console.log(err)
    console.log(data)
})
let four="select * from stu where class=4 order by score  desc limit 3"
con.query(four,(err,data)=>{
     console.log(err)
    console.log(data)
})
con.end();